package tau.adx.common.ads.generators;

import java.util.Collection;
import java.util.LinkedList;
import java.util.Random;

import tau.adx.common.ads.Ad;
import tau.adx.common.ads.properties.AdType;
import tau.adx.common.generators.GenericGenerator;

/**
 * A naive implementation of the {@link GenericGenerator} interface. Randomizes
 * each characteristic of an {@link Ad}.
 * 
 * @author greenwald
 * 
 */
public class SimpleAdGenerator implements GenericGenerator<Ad> {

	/**
	 * @see tau.adx.common.generators.GenericGenerator#generate(int)
	 */
	@Override
	public Collection<Ad> generate(int amount) {
		Collection<Ad> ads = new LinkedList<>();
		for (int i = 0; i < amount; i++) {
			ads.add(getRandomAd());
		}
		return ads;
	}

	/**
	 * @return A {@link Random} {@link Ad}.
	 */
	public static Ad getRandomAd() {
		AdType adType = randomAdType();
		Ad ad = new Ad(adType);
		return ad;
	}

	/**
	 * @return A random {@link AdType}.
	 */
	private static AdType randomAdType() {
		Random random = new Random();
		return AdType.values()[(random.nextInt(AdType.values().length))];
	}
}
